package cn.zcx;

import java.util.concurrent.TimeUnit;

/**
 * description:interrupt()打断
 * author:zcx
 * lenovo
 * 时间：2022.02.07.19.58
 */
public class Ex3 {
    //方法二
    public static void main(String[] args) {
        var t = new Thread(()->{
            while(true){
                try {
                    System.out.println(Thread.currentThread().getName());
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                    System.out.println(Thread.currentThread().getName() + "被中断了");
                    break;
                }
            }
        },"t1");
        t.start();

        try {
            System.out.println(Thread.currentThread().getName());
            TimeUnit.SECONDS.sleep(2);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        t.interrupt();
    }

}
